﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Collections.Specialized;
using System.Data.SqlClient;

namespace PhotoViewer
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
            this.skinEngine1.SkinFile = @"..\..\Skin\DiamondGreen.ssk";
        }

        #region 调用系统API
        [DllImport("user32.dll", EntryPoint = "SystemParametersInfoA")]
        
        //函数原型
        //BOOL WINAPI SystemParametersInfo(
        //UINT uiAction,    //索要执行的操作
        //UINT uiParam,     //用户参数 If not otherwise indicated, you must specify zero for this parameter.
        //PVOID pvParam,   //(要获取或者设置的参数)If not otherwise indicated, you must specify NULL for this parameter. 
        //UINT fWinIni  //This parameter can be zero if you do not want to update the user profile or broadcast the WM_SETTINGCHANGE message, or it can be one or more of the following values.
        //);

        static extern Int32 SystemParametersInfo(Int32 uAction, Int32 uParam, string lpvparam, Int32 fuwinIni);
        private const int SPI_SETDESKWALLPAPER = 20;
        #endregion


        #region 类字段
        public int picIndex; //用于保存图片当前的索引值
        public Bitmap image1;//bitmap对象
        public string imagePath;//图片的路径
        public string pictureWidth;//图片的宽度
        public string pictureHeight;//图片的高度
        public double selectFileSize;//选中的文件夹的大小
        string picDirectory;   //定义变量用于保存用户选择的图片文件夹路径
        string picCount;//照片的总数
        #endregion 

        #region 自定义方法
        /// <summary>
        /// 获取临时文件目录
        /// </summary>
        public string GetTempPath()
        {
            string TemporaryPath;
            TemporaryPath = Application.StartupPath.ToString(); //获取应用程序的执行目录
            TemporaryPath = TemporaryPath.Substring(0, TemporaryPath.LastIndexOf("\\"));
            TemporaryPath = TemporaryPath.Substring(0, TemporaryPath.LastIndexOf("\\"));
            TemporaryPath += @"\TemporaryFolder";
            return TemporaryPath;//得到的是TemporaryFoleder文件夹所在的目录

            //等价于（@"..\..\TemporaryFolder"）
        }

        /// <summary>
        /// ToolStatusUnable 主要用于是某些控件无法使用
        /// </summary>
        public void ToolStatusUnable()
        {
           
            //设置菜单栏无效项
            contextMenuStrip1.Enabled = false;
           
            formatConvertTsMenu.Enabled = false;
            deleteTsMenue.Enabled = false;
            saveASTsMenue.Enabled = false;
            renameTsMenue.Enabled = false;
            setDeskTsMenue.Enabled = false;
            printTsMenue.Enabled = false;
            picSpecialTsMenue.Enabled = false;
            picAdjustTsMenue.Enabled = false;
            picWaterTsMenue.Enabled = false;
            //thumbnailTsMenu.Enabled = false;

            //设置工具栏无效项
            tsbtnRefresh.Enabled = false;
            tsbtnDelete.Enabled = false;
            tsbtnUpward.Enabled = false;
            tsbtnDownward.Enabled = false;
            tsbtnRotate.Enabled = false;
            tsbtnSlideshow.Enabled = false;
        }

        /// <summary>
        /// 按钮有效设置
        /// </summary>
        public void ToolStatusEnable()
        {
            //设置菜单栏无效项
            contextMenuStrip1.Enabled = true;
            formatConvertTsMenu.Enabled = true;
            deleteTsMenue.Enabled = true;
            saveASTsMenue.Enabled = true;
            renameTsMenue.Enabled = true;
            setDeskTsMenue.Enabled = true;
            printTsMenue.Enabled = true;
            picSpecialTsMenue.Enabled = true;
            picAdjustTsMenue.Enabled = true;
            picWaterTsMenue.Enabled = true;

            //设置工具栏有效项
            tsbtnRefresh.Enabled = true;
            tsbtnDelete.Enabled = true;
            tsbtnUpward.Enabled = true;
            tsbtnDownward.Enabled = true;
            tsbtnRotate.Enabled = true;
            tsbtnSlideshow.Enabled = true;
        }
        #endregion

        #region 窗体加载
        /// <summary>
        /// 主窗体加载初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmMain_Load(object sender, EventArgs e)
        {
            //1、加载窗体设置窗体时间
           
            tssCurDate.Text=DateTime.Now.ToString(); //设置状态栏显示当前日期时间

            //this.picBoxShow.Image = Image.FromFile(@"..\..\Image\main1.jpg");

            //2、清空临时文件夹下的所有图像文件
            DirectoryInfo dirInfo = new DirectoryInfo(GetTempPath());//获取TemporaryFolder文件夹所在目录信息
            FileSystemInfo[] fileSysInfo = dirInfo.GetFileSystemInfos();   //获取temporaryFolder下的所有文件

            for (int i = 0; i < fileSysInfo.Length; i++)
            {
                try
                {
                    FileInfo fileInfo = new FileInfo(GetTempPath() + @"\" + fileSysInfo[i].ToString()); //获取到每个文件信息
                    fileInfo.Delete();//删除掉没个文件
                }
                catch
                {
                }
            }

            //3、如果Listbox中的items.count=0(未打开任何文件)，要将相应的按钮设置成unenabled;
            if(listBox1.Items.Count==0)
            {
                ToolStatusUnable();
            }
        }
        #endregion 

        #region 工具栏事件
    
        /// <summary>
        /// 工具栏中打开按钮的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbtnOpen_Click(object sender, EventArgs e)
        {
            if(folderBrowserDialog1.ShowDialog()==DialogResult.OK)
            {
               listBox1.Items.Clear();//清空列表
               picDirectory= folderBrowserDialog1.SelectedPath;  //获取用户所选取图片文件夹路径(目录)

                DirectoryInfo direInfo = new DirectoryInfo(picDirectory);  // 获取该目录的信息
                FileSystemInfo[] fileInfo = direInfo.GetFileSystemInfos(); //获取该目录下的所有文件名+后缀名

                for (int i = 0; i < fileInfo.Length;i++ )
                {
                    //获取每个文件的后缀名，并判定是否是图片格式的
                    string fileType = fileInfo[i].ToString().Substring(fileInfo[i].ToString().LastIndexOf('.') + 1,
                       (fileInfo[i].ToString().Length - fileInfo[i].ToString().LastIndexOf('.') - 1));
                    //string fileType = fileInfo[i].Extension.ToString();

                    fileType.ToLower();

                    //如果是图片类型，则将图片添加到Listbox中
                    if (fileType == "jpg" || fileType == "png" || fileType == "bmp" || fileType == "gif" || fileType == "jpeg")
                    {
                        listBox1.Items.Add(fileInfo[i].ToString());
                    }
                }
                picCount = listBox1.Items.Count.ToString(); //记录整个照片的总数
            }
          
        }




        /// <summary>
        /// 删除按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbtnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure to delete?", "Once deleted you can't restore", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                File.Delete(imagePath);//删除制定的图片

                MessageBox.Show("Deleted successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                //刷新listbox
                tsbtnRefresh_Click(sender, e);
            }
        }

        /// <summary>
        /// 查看上一张图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbtnUpward_Click(object sender, EventArgs e)
        {
            try
            {
                if (listBox1.SelectedIndex != 0)
                {
                    listBox1.SetSelected(listBox1.SelectedIndex - 1, true);
                }
                else
                {
                    MessageBox.Show("This is the first one", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch { }
        }

        /// <summary>
        /// 查看下一张图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbtnDownward_Click(object sender, EventArgs e)
        {
            try
            {
                if (listBox1.SelectedIndex != Convert.ToInt32(picCount) - 1)
                {
                    listBox1.SetSelected(listBox1.SelectedIndex + 1, true);
                }
                else
                {
                    MessageBox.Show("This is the last one", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch { }
        }

        /// <summary>
        /// 图片旋转
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbtnRotate_Click(object sender, EventArgs e)
        {
            Image tempImage = picBoxShow.Image;
            tempImage.RotateFlip(RotateFlipType.Rotate90FlipXY);//顺时针旋转图片90度
            picBoxShow.Image = tempImage;
        }

        /// <summary>
        /// 幻灯片播放
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbtnSlideshow_Click(object sender, EventArgs e)
        {
            frmSlideshow slideshow = new frmSlideshow();
            slideshow.picDiretoryPath = picDirectory;
            slideshow.ShowDialog();
        }

        /// <summary>
        /// 刷新功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbtnRefresh_Click(object sender, EventArgs e)
        {
            if (listBox1.Items.Count == 0)
            {
                tsbtnRefresh.Enabled = false;//如果列表中的图片都被删除了，则刷新功能无法使用
            }
            else
            {
                tsbtnRefresh.Enabled = true;
                listBox1.Items.Clear();//清空listbox中的所有项目

                picBoxShow.Image = null;
                //picBoxShow.Image = picBoxShow.Image;

                //重新导入用户所选择的图片路径中的图片
                DirectoryInfo direInfo = new DirectoryInfo(picDirectory);
                FileSystemInfo[] fileInfo = direInfo.GetFileSystemInfos();
                for (int i = 0; i < fileInfo.Length; i++)
                {
                    string fileType = fileInfo[i].Extension.ToString();
                    fileType.ToLower();
                    //如果是图片类型，则将图片添加到Listbox中
                    if (fileType == ".jpg" || fileType == ".png" || fileType == ".bmp" || fileType == ".gif" || fileType == ".jpeg")
                    {
                        listBox1.Items.Add(fileInfo[i].ToString());
                    }
                }
                ToolStatusUnable();
            }
        }
        #endregion


        #region 事件


        //动态获取系统时间
        private void timer1_Tick_1(object sender, EventArgs e)
        {
            tssCurDate.Text = DateTime.Now.ToString();//每隔interval=1000，就会触发此事件
        }

        /// <summary>
        /// 当listbox中所选择的索引值发生改变时触发该事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (listBox1.Items.Count != 0)
                {
                    ToolStatusEnable(); //当listbox不为空选择图片的时候按钮则回复成可用
                }

                picBoxShow.BackColor = Color.WhiteSmoke;

                string imageName = listBox1.SelectedItem.ToString();//获取图片名

                //if (picDirectory.Length == 4)
                //{
                //    imagePath =picDirectory+ imageName;
                //}
                //else
                //{
                //    imagePath =picDirectory+ "\\" + imageName;
                //}

                imagePath =picDirectory+ @"\" + imageName;


                //清空temporaryFolder下的所有文件
                DirectoryInfo DInfo = new DirectoryInfo(GetTempPath());
                FileSystemInfo[] fileSysInfo = DInfo.GetFileSystemInfos();

                for (int i = 0; i < fileSysInfo.Length; i++)
                {
                    try
                    {
                        FileInfo fInfo = new FileInfo(GetTempPath() + "\\" + fileSysInfo[i].ToString());
                        fInfo.Delete();
                    }
                    catch
                    { }
                }

                //将每次打开的文件存入到TemporaryFolder中
                string newFilePath;
               // string SFileType = imagePath.Substring(imagePath.LastIndexOf(".") + 1,
                //(imagePath.Length - imagePath.LastIndexOf(".") - 1));

                //获取临时文件的路径
                FileInfo fInfos = new FileInfo(GetTempPath() + "\\" + imageName);
                if (fInfos.Exists)
                {
                    //如果临时文件夹中已经存在该图片
                    newFilePath = GetTempPath() + "\\" + imageName;
                }
                else
                {
                    //如果该图片还未在TemporaryFile中则现将该文件copy到TemporaryFolder中
                    File.Copy(imagePath, GetTempPath() + "\\" + imageName, true);
                    newFilePath = GetTempPath() + "\\" + imageName;
                }

                //将temporaryFolder中的文件显示在PictureBox中
                picBoxShow.Image = Image.FromFile(newFilePath);

                image1 = new Bitmap(newFilePath);
                //获取图片大小
                pictureWidth = image1.Width.ToString();
                pictureHeight = image1.Height.ToString();

                FileInfo fileInfo = new FileInfo(newFilePath);
                string FileSize = fileInfo.Length.ToString();

                selectFileSize = Convert.ToDouble(FileSize) / 1024 / 1024;  //将文件大小换算成M
                btnShowPicInfo.Text = "图片大小：" + selectFileSize.ToString("F") + "M   "
                    + "分辨率：" + pictureWidth + "×" + pictureHeight;
                image1.Dispose();

                tssPicCount.Text = picCount;    //图片总数
                tssCurrentPic.Text = Convert.ToString(listBox1.SelectedIndex + 1);    //当前图片为第几张

                //见/设置成可见的
                toolStripStatusLabel3.Visible = true;
                //contextMenuStrip1.Enabled = true;
                ToolStatusEnable();

                picIndex = listBox1.SelectedIndex;//当前选图片的索引值引值

            }
            catch { }
        }
    
        /// <summary>
        /// 单击图片，图片则以最大化形式显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picBoxShow_Click(object sender, EventArgs e)
        {
            //如果picbox中有图片，单击则以最大化进行显示
            if (picBoxShow.Image!=null)
            {
                frmPictureMax pictureMax = new frmPictureMax();
                pictureMax.imagePath = imagePath;
                pictureMax.pictureWidth = pictureWidth;
                pictureMax.pictureHeight = pictureHeight;
                pictureMax.selectFileSize = selectFileSize;
                pictureMax.ShowDialog();
            }
        }

        /// <summary>
        /// PrintDocument1_PrintPage事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            int printWidth = printDocument1.DefaultPageSettings.PaperSize.Width;
            int printHeight = printDocument1.DefaultPageSettings.PaperSize.Height;

            //如果照片的宽度小雨打印文档默认宽度，则可以直接进行绘制
            if (Convert.ToInt32(pictureWidth) < printWidth)
            {
                int x = (printWidth - Convert.ToInt32(pictureWidth)) / 2;
                int y = (printHeight - Convert.ToInt32(pictureHeight)) / 2;
                e.Graphics.DrawImage(Image.FromFile(imagePath), x, y, Convert.ToInt32(pictureWidth), Convert.ToInt32(pictureHeight));
            }
            else
            {
                if (Convert.ToInt32(pictureWidth) > Convert.ToInt32(pictureHeight))
                {
                    //如果宽度大于高度则进行旋转

                    Bitmap bitmap = new Bitmap(imagePath);
                    bitmap.RotateFlip(RotateFlipType.Rotate90FlipXY);//xy轴进行旋转90度
                    PictureBox pictureBox = new PictureBox();
                    pictureBox.Image = bitmap;

                    //参考msdn
                    Single a = printWidth / Convert.ToSingle(pictureHeight);
                    e.Graphics.DrawImage(pictureBox.Image, 0, 0, Convert.ToSingle(pictureHeight) * a, Convert.ToSingle(pictureWidth) * a);
                }
                else
                {

                    Single a = printWidth / Convert.ToSingle(pictureWidth);
                    e.Graphics.DrawImage(Image.FromFile(imagePath), 0, 0, Convert.ToSingle(pictureWidth) * a, Convert.ToSingle(pictureHeight) * a);
                }
            }
        }

        #endregion


        #region 图片格式转换
        /// <summary>
        /// 将图片保存为bmp格式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bMPToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //获取图片名称
            string imageName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1, (imagePath.LastIndexOf(".") - imagePath.LastIndexOf("\\") - 1));

            //保存imageName之前的目录
            string newPath = imagePath.Remove(imagePath.LastIndexOf("\\"));//除掉imageName
            newPath += "\\";

            //获取picbox中的图片，并保存为指定的格式
            Bitmap bitMap = new Bitmap(picBoxShow.Image);
            bitMap.Save(newPath + imageName + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);

            //将源文件中的图片删除并且刷新图片
            FileInfo fileInfo = new FileInfo(imagePath);
            fileInfo.Delete();

        }

        /// <summary>
        /// 将图片保存为gif格式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gIFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //获取图片名称
            string imageName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1, (imagePath.LastIndexOf(".") - imagePath.LastIndexOf("\\") - 1));

            //保存imageName之前的目录
            string newPath = imagePath.Remove(imagePath.LastIndexOf("\\"));//除掉imageName
            newPath += "\\";

            //获取picbox中的图片，并保存为指定的格式
            Bitmap bitMap = new Bitmap(picBoxShow.Image);
            bitMap.Save(newPath + imageName + ".gif", System.Drawing.Imaging.ImageFormat.Gif);

            //将源文件中的图片删除并且刷新图片
            FileInfo fileInfo = new FileInfo(imagePath);
            fileInfo.Delete();
            tsbtnRefresh_Click(sender, e);

        }

        /// <summary>
        ///将图片转换为jpg格式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void jPGToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //获取图片名称
            string imageName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1, (imagePath.LastIndexOf(".") - imagePath.LastIndexOf("\\") - 1));

            //保存imageName之前的目录
            string newPath = imagePath.Remove(imagePath.LastIndexOf("\\"));//除掉imageName
            newPath += "\\";

            //获取picbox中的图片，并保存为指定的格式
            Bitmap bitMap = new Bitmap(picBoxShow.Image);
            bitMap.Save(newPath + imageName + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

            //将源文件中的图片删除并且刷新图片
            FileInfo fileInfo = new FileInfo(imagePath);
            fileInfo.Delete();
            tsbtnRefresh_Click(sender, e);

        }

        /// <summary>
        /// 将图片转换为png
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pNGToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //获取图片名称
            string imageName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1, (imagePath.LastIndexOf(".") - imagePath.LastIndexOf("\\") - 1));

            //保存imageName之前的目录
            string newPath = imagePath.Remove(imagePath.LastIndexOf("\\"));//除掉imageName
            newPath += "\\";

            //获取picbox中的图片，并保存为指定的格式
            Bitmap bitMap = new Bitmap(picBoxShow.Image);
            bitMap.Save(newPath + imageName + ".png", System.Drawing.Imaging.ImageFormat.Png);

            //将源文件中的图片删除并且刷新图片
            FileInfo fileInfo = new FileInfo(imagePath);
            fileInfo.Delete();
            tsbtnRefresh_Click(sender, e);

        }
        #endregion

        /// <summary>
        /// 菜单栏打开按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openTsMenue_Click(object sender, EventArgs e)
        {
            tsbtnOpen_Click(sender, e);
        }

        /// <summary>
        /// 菜单删除按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteTsMenue_Click(object sender, EventArgs e)
        {
            tsbtnDelete_Click(sender, e);
        }

        /// <summary>
        /// 菜单另存为按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveASTsMenue_Click(object sender, EventArgs e)
        {
            try
            {
                //过滤器声明由 说明|后缀名 组成
                saveFileDialog1.Filter = "BMP|*.bmp|JPEG|*.jpeg|GIF|*.gif|PNG|*.png";
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    string picPath = saveFileDialog1.FileName;//为文件保存的路径

                    string picType = picPath.Substring(picPath.LastIndexOf(".") + 1, picPath.Length - picPath.LastIndexOf(".") - 1);    //获取文件的后缀名

                    //将图片保存为相应的格式
                    switch (picType)
                    {
                        case "bmp":
                            //将源文件imagepath保存到新路径
                            Bitmap bitMap = new Bitmap(imagePath);
                            bitMap.Save(picPath, System.Drawing.Imaging.ImageFormat.Bmp);
                            break;
                        case "jpeg":
                            Bitmap jpgMap = new Bitmap(imagePath);
                            jpgMap.Save(picPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                            break;
                        case "gif":
                            Bitmap gifMap = new Bitmap(imagePath);
                            gifMap.Save(picPath, System.Drawing.Imaging.ImageFormat.Gif);
                            break;
                        case "png":
                            Bitmap pngMap = new Bitmap(imagePath);
                            pngMap.Save(picPath, System.Drawing.Imaging.ImageFormat.Png);
                            break;
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        /// <summary>
        /// 重新命名功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void renameTsMenue_Click(object sender, EventArgs e)
        {
            string imageName = imagePath.Substring(imagePath.LastIndexOf("\\") + 1, (imagePath.LastIndexOf(".") - imagePath.LastIndexOf("\\") - 1));
            string imageType = imagePath.Substring(imagePath.LastIndexOf(".") + 1, (imagePath.Length - imagePath.LastIndexOf(".") - 1));
            frmPicRename rename = new frmPicRename();
            rename.imageName = imageName;
            rename.imagePath = imagePath;
            rename.imageType = imageType;
            rename.ShowDialog();

            //刷新列表
            tsbtnRefresh_Click(sender, e);
        }

        /// <summary>
        /// 设置桌面背景
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void setDeskTsMenue_Click(object sender, EventArgs e)
        {
            SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imagePath, 1); //调用系统API函数
        }

        /// <summary>
        /// 打印功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void printTsMenue_Click(object sender, EventArgs e)
        {
            printPreviewDialog1.Document = printDocument1;//设置要打印的文档
            printPreviewDialog1.ShowDialog();
        }

        /// <summary>
        /// 退出应用程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void exitTsMenue_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("Are you sure to exit?","Prompt",MessageBoxButtons.OKCancel,MessageBoxIcon.Information)==DialogResult.OK)
            {
                Application.Exit();
            }
        }


        #region 菜单栏window的设置
        /// <summary>
        /// 设置状态栏是否可见
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void statusBarTstMenue_Click(object sender, EventArgs e)
        {
            if (statusBarTstMenue.CheckState == CheckState.Checked)
            {
                statusBarTstMenue.CheckState = CheckState.Unchecked;//若悬钟则设置为未选，并不现实状态栏
                statusStrip1.Visible = false;
            }
            else
            {
                statusBarTstMenue.CheckState = CheckState.Checked;
                statusStrip1.Visible = true;
            }
        }

        /// <summary>
        /// 设置工具栏可见与不可见
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolBarTsMenue_Click(object sender, EventArgs e)
        {
            if (toolBarTsMenue.CheckState == CheckState.Checked)
            {
                toolBarTsMenue.CheckState = CheckState.Unchecked;
                toolStrip1.Visible = false;
            }
            else
            {
                toolBarTsMenue.CheckState = CheckState.Checked;
                toolStrip1.Visible = true;
            }
        }

        /// <summary>
        /// 设置图片信息是否可见
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picInfoTsMenue_Click(object sender, EventArgs e)
        {
            if (picInfoTsMenue.CheckState == CheckState.Checked)
            {
                picInfoTsMenue.CheckState = CheckState.Unchecked;
                btnShowPicInfo.Visible = false;
            }
            else
            {
                picInfoTsMenue.CheckState = CheckState.Unchecked;
                btnShowPicInfo.Visible = true;
            }
        }
        #endregion

        #region 右键菜单栏事件
        /// <summary>
        /// 右键菜单中的复制功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StringCollection filePath = new StringCollection();//将每一个字符串作为一个元素
            filePath.Add(imagePath);
            Clipboard.SetFileDropList(filePath);//filedroplist将文件信息转换成string array 并保存在clipboard中
        }  

        private void deleteToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            tsbtnDelete_Click(sender, e);
        }

        private void refreshToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            tsbtnRefresh_Click(sender, e);
        }

        private void renameToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            renameTsMenue_Click(sender, e);
        }

        private void printToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            printTsMenue_Click(sender, e);
        }

        private void setAsDesktopBackgroundToolStripMenuItem_Click(object sender, EventArgs e)
        {
            setDeskTsMenue_Click(sender, e);
        }

        private void saveAsToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            saveASTsMenue_Click(sender, e);
        }
        #endregion

        #region 图片设置
        /// <summary>
        /// 图片增加文字水印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picWaterTsMenue_Click(object sender, EventArgs e)
        {
            if (picBoxShow.Image != null)
            {
                frmPicWater water = new frmPicWater();
                water.image = picBoxShow.Image;
                water.imagePath = imagePath;
                water.ShowDialog();
            } 
        }

        /// <summary>
        /// 图片亮度、对比度
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picAdjustTsMenue_Click(object sender, EventArgs e)
        {
            frmPicAdjust picAdjust = new frmPicAdjust();
            picAdjust.image = picBoxShow.Image;
            picAdjust.imageOldPath = imagePath;
            picAdjust.ShowDialog();
        }

        /// <summary>
        /// 图片特效设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picSpecialTsMenue_Click(object sender, EventArgs e)
        {
            if (listBox1.Items.Count != 0)
            {
                frmSpecialEfficacy specialEfficacy = new frmSpecialEfficacy();
                specialEfficacy.image = picBoxShow.Image;
                specialEfficacy.ShowDialog();
            }
        }
        #endregion

        /// <summary>
        /// 打开一个图片文件夹之后幻灯片形式播放照片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void thumbnailTsMenu_Click(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// 随机更换主题
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void themesTsMenu_Click(object sender, EventArgs e)
        {
            Random random = new Random();
            int num=random.Next(9);
            switch (num)
            { 
                case 0:
                    this.skinEngine1.SkinFile = @"..\..\Skin\DiamondBlue.ssk";
                    break;
                case 1:
                    this.skinEngine1.SkinFile = @"..\..\Skin\SteelBlack.ssk";
                    break;
                case 2:
                    this.skinEngine1.SkinFile = @"..\..\Skin\DiamondGreen.ssk";
                    break;
                case 3:
                    this.skinEngine1.SkinFile = @"..\..\Skin\OneGreen.ssk";
                    break;
                case 4:
                    this.skinEngine1.SkinFile = @"..\..\Skin\SportBlue.ssk";
                    break;
                case 5:
                    this.skinEngine1.SkinFile = @"..\..\Skin\GlassBrown.ssk";
                    break;
                case 6:
                    this.skinEngine1.SkinFile = @"..\..\Skin\WarmColor3.ssk";
                    break;
                case 7:
                    this.skinEngine1.SkinFile = @"..\..\Skin\EmeraldColor1.ssk";
                    break;
                case 8:
                    this.skinEngine1.SkinFile = @"..\..\Skin\Wave.ssk";
                    break;
                case 9:
                    this.skinEngine1.SkinFile = @"..\..\Skin\WaveColor2.ssk";
                    break;
            }
        }

        private void tsbtnCamera_Click(object sender, EventArgs e)
        {
            frmCamera camera = new frmCamera();
            camera.ShowDialog();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("TTPlayer");
        }

        private void exitTsMenu_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

    }
}
